package servletTest;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/ok")
public class ServletTest1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应和返回数据编码
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        System.out.println("66666");
        //接值
        Integer requestAttribute = (Integer) req.getAttribute("name");
        System.out.println("requestAttribute = " + requestAttribute);
        //生成页面
        PrintWriter writer = resp.getWriter();
        writer.write("" +
                "<!doctype html>" +
                "<html>" +
                "<head>" +
                "<title>服务器生成页面</title><meta charset='utf-8'>" +
                "</head>" +
                "<body>" +
                "<h1>服务器端开发</h1>" +
                "</body>" +
                "</html>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
